<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="名称" prop="postName">
        <el-input
          v-model="queryParams.postName"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="postList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center"/>
      <!-- <el-table-column label="岗位编号" align="center" prop="postId" /> -->
      <el-table-column label="姓名" align="center" prop="name" width="100">
        <template slot-scope="scope">
          {{ scope.row.sysUser ? scope.row.sysUser.nickName : `未知ID${scope.row.userId}` }}
        </template>
      </el-table-column>
      <el-table-column label="打卡时间" align="center" prop="name">
        <template slot-scope="scope">
          <!--        0-未打卡1-已打卡2-迟到/早退3-旷工4-不用打卡-->
          <!--          endType1-->
          <!--          endType2-->
          <!--          startType1-->
          <!--          startType2-->
          <p v-if="scope.row.startTime1 || scope.row.endTime1" class="log-line">
            <span>
              {{ scope.row.startTime1 }}
              <em>{{logStatus[scope.row.startType1]}}</em>
            </span>
            -
            <span>
              {{ scope.row.endTime1 }}
              <em>{{logStatus[scope.row.endType1]}}</em>
            </span>
          </p>
          <p v-if="scope.row.startTime2 || scope.row.endTime2" class="log-line">
            <span>
              {{ scope.row.startTime2 }}
              <em>{{logStatus[scope.row.startType2]}}</em>
            </span>
            -
            <span>
              {{ scope.row.endTime2 }}
              <em>{{logStatus[scope.row.endType2]}}</em>
            </span>
          </p>
        </template>
      </el-table-column>
<!--      <el-table-column-->
<!--        label="操作"-->
<!--        align="center"-->
<!--        class-name="small-padding fixed-width"-->
<!--        width="120"-->
<!--      >-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['system:post:remove']"-->
<!--          >删除-->
<!--          </el-button-->
<!--          >-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {signLog} from "@/api/system/sign_category";

export default {
  name: "Post",
  dicts: ['sys_normal_disable'],
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        postName: [
          {required: true, message: "岗位名称不能为空", trigger: "blur"}
        ],
        postCode: [
          {required: true, message: "岗位编码不能为空", trigger: "blur"}
        ],
        postSort: [
          {required: true, message: "岗位顺序不能为空", trigger: "blur"}
        ]
      },
      detailVisible: false,
      paramId: 0,
      logStatus: {
        0: '未打卡',
        1: '已打卡',
        2: '迟到/早退',
        3: '旷工',
        4: '不用打卡'
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      signLog(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.paramId = 0
      this.detailVisible = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.paramId = row.id
      this.detailVisible = true
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const postIds = row.postId || this.ids;
      this.$modal.confirm('是否确认删除岗位编号为"' + postIds + '"的数据项？').then(function () {
        return delProjectPost(postIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
  }
};
</script>
<style>
.log-line em{
  font-style: normal;
  font-size: 12px;
  padding: 2px;
  background: #f4f4f4;
  border-radius: 5px;
  color: #2a99ff;
}
</style>
